package com.weixing.mall.provider.controller.sys;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.dto.sys.SysDeptDto;
import com.weixing.mall.provider.model.vo.sys.SysDeptCascaderVo;
import com.weixing.mall.provider.service.IDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: kfc
 * @Description: <br/>
 * Date:Create in 2019/7/25 16:13
 * @Modified By:
 */
@RestController
@Api(value = "组织结构Api",tags = "组织结构")
@RequestMapping("dept")
public class SysDeptController extends BaseController {

    @Autowired
    private IDeptService sysDeptService;

    @ApiOperation(value = "加载组织结构")
    @GetMapping("")
    public Result list(){
        return ResultUtil.success(sysDeptService.selectTree());
    }

    @ApiOperation("添加")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@Validated SysDeptDto sysDeptDto){
        sysDeptService.save(sysDeptDto);
        return ResultUtil.success();
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id",paramType = "path",dataType = "long")
    })
    @PostMapping("del/{id}")
    public Result del(@PathVariable Long id){

        return sysDeptService.removeById(id)  ? ResultUtil.success():ResultUtil.error();
    }

    @ApiOperation(value = "查询-用于select级联")
    @GetMapping("form")
    public Result form(){
        List<SysDeptCascaderVo> list = sysDeptService.selectSysDeptCascaderVo();
        return ResultUtil.success(list);
    }

}
